package com.prd.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.prd.config.LoginInterceptor;
import com.prd.dto.OaDepartEvaluateDTO;
import com.prd.model.LoginUser;
import com.prd.model.OaDepartEvaluateDO;
import com.prd.service.OaDepartEvaluateService;
import com.prd.util.CommonUtil;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 离职评价记录表 前端控制器
 * </p>
 *
 * @author lizhaoyi
 * @since 2024-01-01
 */
@RestController
@RequestMapping("/api/oaDepartEvaluate")
@Api(tags = "离职评价相关接口")
public class OaDepartEvaluateController {

    @Autowired
    private OaDepartEvaluateService oaDepartEvaluateService;

    @ApiOperation("补充离职评价")
    @PostMapping("add")
    public JsonData add(@RequestBody OaDepartEvaluateDTO oaDepartEvaluateDTO){

        OaDepartEvaluateDO oaDepartEvaluateDO = CommonUtil.dtoTransfer(oaDepartEvaluateDTO, OaDepartEvaluateDO.class);
        oaDepartEvaluateDO.setCreatedBy(LoginInterceptor.threadLocal.get().getName());
        oaDepartEvaluateDO.setCreatedTime(LocalDateTime.now());
        oaDepartEvaluateService.saveOrUpdate(oaDepartEvaluateDO);

        return JsonData.buildSuccess();
    }

    @ApiOperation("查询离职评价列表")
    @PostMapping("list")
    public JsonData list(@ApiParam("离职记录id") @RequestParam(value = "departId") String departId){

        return JsonData.buildSuccess(oaDepartEvaluateService.list(new LambdaQueryWrapper<OaDepartEvaluateDO>().eq(OaDepartEvaluateDO::getDepartId,departId)));
    }

    @ApiOperation("查询离职评价详情")
    @PostMapping("detail")
    public JsonData detail(@ApiParam("离职评价id") @RequestParam(value = "id") String id){

        return JsonData.buildSuccess(oaDepartEvaluateService.getById(id));
    }

}

